<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/30
 * Time: 13:51
 */

namespace app\index\server;


use app\index\model\CardDaybook as CardDaybookModel;
use app\index\model\UserDaybook as UserDaybookModel;

class DaybookServer extends BaseServer
{
    public function getCardList($params = [])
    {
        $params = $this->prep_param($params);
        try {
            // 总条数
            $count = CardDaybookModel::count();
            $list = CardDaybookModel::with(['card'])
                ->order($params['sort'], $params['order'])
                ->limit($params['offset'], $params['limit'])
                ->select();
        } catch (Exception $e) {
            throw new DatabaseException([
                'msg' => $e->getMessage()
            ]);
        }
        return bootstrap_table_return($count, $list);
    }

    public function getUserList($params = [])
    {
        $params = $this->prep_param($params);
        try {
            // 总条数
            $count = UserDaybookModel::count();
            $list = UserDaybookModel::with(['user'])
                ->order($params['sort'], $params['order'])
                ->limit($params['offset'], $params['limit'])
                ->select();
        } catch (Exception $e) {
            throw new DatabaseException([
                'msg' => $e->getMessage()
            ]);
        }
        return bootstrap_table_return($count, $list);
    }
}